package com.dream.cgomall.service.impl;

import com.dream.cgomall.dao.CgoGoodPictureDao;
import com.dream.cgomall.entity.CgoGoodPicture;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class CgoGoodsPictureImpl {
    @Autowired
    private CgoGoodPictureDao cgoGoodPictureDao;

    /**
     *
     * @param id 商品id
     * @return key 是商品图片的位置   value 商品图片
     */
    public Map<String,List<CgoGoodPicture>> cgoGoodPicture(Integer id){
        List<CgoGoodPicture> cgoGoodPictureList = cgoGoodPictureDao.findGoodsPicture(id);
        //通过stream对商品图片布局进行分组 key是商品布局  value 是图片
        Map<String, List<CgoGoodPicture>> collect = cgoGoodPictureList.stream()
                .collect(Collectors.groupingBy(CgoGoodPicture::getPictureIntroduceId));
        return collect;
    }
}
